import fetch from "@/utils/http";
import type {
  AddPermissionParams,
  DictionaryAddRequest,
  DictionaryResponse,
  DictionaryUpdateRequest,
  EditPermission,
  LinkMenuParams,
  LinkPermissionParams,
  OperatorAddRequest,
  OperatorLinkCompany,
  OperatorLinkRoleParams,
  OperatorUpdateRequest,
  PageOperatorResponse,
  PageParams,
  PagePermissionResponse,
  PageRoleResponse,
  PermissionResponse,
  RoleResponse
} from "./system";
import { MenuResponse } from "../menu/menu";
/**
 * 获取权限列表
 * @param data
 * @returns
 */
export function getPermission(data: PageParams) {
  return fetch<PagePermissionResponse>("/v1/permission/page", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 添加权限
 * @param data
 * @returns
 */
export function addPermission(data: AddPermissionParams) {
  return fetch("/v1/permission/add", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 更新权限
 * @param data
 * @returns
 */
export function editPermission(data: EditPermission) {
  return fetch("/v1/permission/update", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 删除权限
 * @param permissionId
 * @returns
 */
export function removePermission(permissionId: string) {
  return fetch(`/v1/permission/remove/${permissionId}`, "MANGMENT", {
    method: "get"
  });
}
/**
 * 获取角色列表
 * @param data
 * @returns
 */
export function getRoleList(data: PageParams) {
  return fetch<PageRoleResponse>("/v1/role/page", "HR", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 添加角色
 * @param data
 * @returns
 */
export function addRole(data) {
  return fetch("/v1/role/add", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}

/**
 * 编辑角色
 * @param data
 * @returns
 */
export function editRole(data) {
  return fetch("/v1/role/update", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 删除角色
 * @param permissionId
 * @returns
 */
export function removeRole(roleId: string) {
  return fetch(`/v1/role/remove/${roleId}`, "MANGMENT", {
    method: "get"
  });
}
/**
 * 角色关联菜单
 * @param data
 * @returns
 */
export function linkMenu(data: LinkMenuParams) {
  return fetch("/v1/role/link/menu", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 获取角色对应的菜单列表
 * @param roleId
 * @returns
 */
export function getRoleMenuList(roleId: string) {
  return fetch<MenuResponse[]>(`/v1/role/menu/${roleId}`, "MANGMENT", {
    method: "post"
  });
}
/**
 * 角色关联权限
 * @param data
 * @returns
 */
export function linkPermission(data: LinkPermissionParams) {
  return fetch("/v1/role/link/permission", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 当前用户相关角色
 * @returns
 */
export function roleMy() {
  return fetch<RoleResponse[]>("/v1/role/my", "HR", {
    method: "post"
  });
}
/**
 * 获取角色对应的权限列表
 * @param roleId
 * @returns
 */
export function getRolePermissionList(roleId: string) {
  return fetch<PermissionResponse[]>(
    `/v1/role/permission/${roleId}`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}

/**
 * 获取操作员列表
 * @param data
 * @returns
 */
export function getOperatorList(data: PageParams) {
  return fetch<PageOperatorResponse>("/v1/operator/page", "HR", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 添加操作员
 * @param data
 * @returns
 */
export function addOperator(data: OperatorAddRequest) {
  return fetch<string>("/v1/operator/add", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 编辑操作员
 * @param data
 * @returns
 */
export function editOperator(data: OperatorUpdateRequest) {
  return fetch("/v1/operator/update", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}

/**
 * 管理员角色关联
 * @param data
 * @returns
 */

export function operatorLinkRole(data: OperatorLinkRoleParams) {
  return fetch("/v1/operator/link/role", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 管理员公司关联
 * @param data
 * @returns
 */

export function operatorLinkCompany(data: OperatorLinkCompany) {
  return fetch("/v1/operator/link/role", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 获取一个用户的角色列表
 */
export function getRoleListByOperator(operatorId: string) {
  return fetch<RoleResponse[]>(`/api/v1/role/list/${operatorId}`, "MANGMENT", {
    method: "post"
  });
}
export function getAllRole() {
  return fetch<RoleResponse[]>(`/api/v1/role/all`, "MANGMENT", {
    method: "get"
  });
}
/**
 * 获取所有字典
 * @returns
 */
export function getAllDicitionaryList() {
  return fetch<DictionaryResponse[]>(`/v1/dict/all`, "HR", {
    method: "get"
  });
}
/**
 * 添加字典
 * @param data
 * @returns
 */
export function dictAdd(data: DictionaryAddRequest) {
  return fetch(`/v1/dict/add`, "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 编辑字典
 * @param data
 * @returns
 */
export function editDic(data: DictionaryUpdateRequest) {
  return fetch(`/v1/dict/update`, "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 删除字典
 * @returns
 */
export function removeDicItem(id: string) {
  return fetch(`/v1/dict/remove/${id}`, "MANGMENT", {
    method: "get"
  });
}
